package com.moon.game.manager;

import java.util.ArrayList;
import java.util.HashMap;

import org.apache.log4j.Logger;

import com.moon.game.constants.Constants;
import com.moon.game.resource.model.LevelExp;

/**
 * @description 当前等级升到下一等级经验对应数据加载
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-5-26 下午4:41:32
 */
public class LevelExpMG {
	private static final Logger log = Logger.getLogger(MonsterMG.class);
	private static HashMap<Integer, Integer> levelForExp = new HashMap<Integer, Integer>();
	private LevelExpMG() {
	}
	public static LevelExpMG instance = new LevelExpMG();
	public void init() {
		log.debug("load levelExps start...");
		loadLevelExps();
		log.debug("load levelExps end...");
	}
	
	/**
	 * 加载等级经验对应表
	 * 
	 */
	private void loadLevelExps() {
		ArrayList<LevelExp> levelExps = (ArrayList<LevelExp>) DBManager.queryAllLevelExp();
		for (LevelExp levelExp:levelExps) {
			levelForExp.put(levelExp.getId(), levelExp.getExp());
			if (levelExp.getId() > Constants.PLAYER_MAX_LEVEL) {
				Constants.PLAYER_MAX_LEVEL = levelExp.getId();
			}
		}
		
		System.err.println(Constants.PLAYER_MAX_LEVEL);
	}
	
	
	/**
	 * 获得升级需要的经验值
	 * 
	 * @param level
	 * @return
	 */
	public final Integer getLevelForExp(int level) {
		return levelForExp.get(level);
	}

}
